<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ include file="/common/taglib.jsp"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
		<sfa:mainTitle></sfa:mainTitle>
		<%@ include file="/common/meta.jsp"%>


<link rel="stylesheet" type="text/css"
			href="${path}/css/step/an.css" >

<style type="text/css">
* {
	margin: 0;
	padding: 0;
}

.tc_box {
	width: 400px;
	height: 200px;
	border: 2px solid red;
	position: absolute;
	z-index: 2000;
	background: #FFC;
	display: none;
}

.sp_box {
	width: 100%;
	position: absolute;
	z-index: 1000;
	background: #000;
	top: 0;
	left: 0;
	display: none;
}

.main .formdiv {
	width: 400px;
}
</style>


<script type="text/javascript" src="${path}/ckeditor/ckeditor.js"></script>
<script type="text/javascript" src="${path}/ckfinder/ckfinder.js"></script>
<script type="text/javascript" src="/ckeditor/ckeditor.js?t=B37D54V"></script>
<link rel="stylesheet" href="${path }/css/affixUpload.css" type="text/css"></link>
		<script type="text/javascript" src="${path}/script/affixUpload.js"></script>

<script type="text/javascript">

$(function() {
	
	//初始化控件 --1
	var actionPath = "${path}/affix/index/upload/SALENEWS";
	var div = 'sfaUpload'
	sfaUpload.init(actionPath,div);


	//清空相关
	$("#clear").click(function(){
		$(".inputbox").val("");
		$(".areabox").val("");
	});
	
	//下一步
	$("#next").click(function(){
	//alert("dddddddddd");
		
	var url="${path}/manage/news/index/validate";
		var title=$("#newsTitle").val();

		var content=CKEDITOR.instances.newsContent.getData();
	
		var param={"newsTitle":title,"newsContent":content};
		$.post(url,param,function(data){
		
			var json=eval(data);
			//alert(json);
        	if(json.result==true)
        	{
	        	$("#step2").css("display","block");
				$("#step1").css("display","none");
				
				$("#firstStep").attr("class", "");
				$("#firstStep_line").attr("class","line_last");
				$("#secondStep").attr("class","now");
				$("#secondStep_line").attr("class","line_frist");
        	}else
        	{
        		$(".newsTitle").html(json.newsTitle);
        		$(".newsContent").html(json.newsContent);
        	}
        	});
		
		
	});
	
	
	$("#provi").click(function() {

				$("#step2").css("display", "none");
				$("#step1").css("display", "block");
				

				$("#firstStep").attr("class", "now");
				$("#firstStep_line").attr("class","line_frist");
				$("#secondStep").attr("class","");
				$("#secondStep_line").attr("class","line");


	});
	
	//提交
	$("#submit").click(function(){
		
		if (sfaUpload.getIsUploading()) {
			art.dialog( {
				content : "文件正在上传,请先取消上传文件！",
				lock : true,
				ok : true
			});
			return;
		}
		
		//alert("sssssssss");
		var saleNewsId="${new.saleNewsId}";
		//alert(saleNewsId);
	var url="${path}/manage/news/index/edit";
		var title=$("#newsTitle").val();
		var content=CKEDITOR.instances.newsContent.getData();
		var type=$("#newType").val();
		var level=$("#agentLevel").val();
		
		var branch=$("input[name='branchId']:checked");
		
		var branchs="";

		if(branch!=null)
		{
			for(var i=0;i<branch.length;i++)
			{
				branchs=(branchs+branch.get(i).value)+(((i+1)==branch.length)?'':',');
			}
		}
		
		var isShare=$("input[name='isShare']:checked").val();
		var inSendto=$("input[name='inSendto']:checked").val();
		var isAffix=$("input[name='isAffix']:checked").val();
		var affixPat=$("input[name='affixPat']").val();
		var createUid=$("#createUid").val();
		var affixStr="";
		$(".uoloadedFile").each(function(i,o){
			var obj=$(o);
			affixStr +=obj.attr("SALEAFFIXITEMID")+";"+obj.attr("isDel")+";;";
		});
		var param={"newsTitle":title,"newsContent":content,"newType":type,"agentLevel":level,
		"branchId":branchs,"isShare":isShare,"inSendto":inSendto,"affixStr":affixStr,
		"isAffix":isAffix,"affixPat":affixPat,"createUid":createUid,"saleNewsId":saleNewsId};
		$.post(url,param,function(data){
			var json=eval(data);
			//alert(json);
        	if(json.result==true)
        	{
	        	$("#step3").css("display","block");
	        	$("#step2").css("display","none");
	        	

				$("#firstStep_line").attr("class","line");
				$("#secondStep").attr("class", "");
				$("#secondStep_line").attr("class","line_last");
				$("#thirdStep").attr("class","now");
				$("#thirdStep_line").attr("class","line_over");
        	}else
        	{
        		$(".newsTitle").html(json.newsTitle);
        		$(".newsContent").html(json.newsContent);
        		$(".affixPat").html(json.affixPat);
        		$(".branch").html(json.branch);
        	}
        	$(".add").html(json.add);
        	});
		
		
	});
	//分析所有分公司进行数据回显
	var branchids='${branchids}';
	branchids=branchids.substring(1,branchids.length-1);
	branchids=branchids.split(",");
	//alert(branchids.length);
	  var boxObj = $("input[name='branchId']");  //获取所有的复选框 
     var index = 0;
     for(i=0;i<boxObj.length;i++){
        for(j=0;j<branchids.length;j++){            
            if(boxObj[i].value == branchids[j].replace(/^\s+|\s+$/g,""))  //如果值与修改前的值相等
            {
                boxObj[i].checked= true;
                break;
            }
        }
     }     
     
    //选择总公司，则其它公司不可选
     $("input[name='branchId']").change(function(){
     	var cur=$(this);
     if(cur.attr("value")=="BRA0000000000001" )
     {
     	if($("input[name='branchId'][value='BRA0000000000001']:checked").length==0)
     	{
     		cur.attr("checked","checked");
     		
     		$("input[name='branchId'][value!='BRA0000000000001']").removeAttr("checked");
     	}else
     	{
     		cur.removeAttr("checked");
     		
     	}
     }else
     {
     	
     	if($("input[name='branchId']:checked").length==0)
     	$("input[name='branchId'][value='BRA0000000000001']").attr("checked","checked");
     	else
     	$("input[name='branchId'][value='BRA0000000000001']").removeAttr("checked");
     }
     });
     
     
     var usertype="${user.userType}";
   if(usertype!='USERTYPE_3')
     {
     	$("input[name='branchId']").attr("disabled","disabled");
     }
});
</script>

<link rel="stylesheet" type="text/css" href="${path}/css/addnews/step1.css" id="step">

	</head>



	<body id="master">

		<sfa:mainHeader></sfa:mainHeader>
		<!--右边-->
            <div class="webpart3 contentarea">
                <div class="webpart-head">
                    <div class="webpart-head-item">
                        编辑公告
                    </div>
                </div>
                <div class="webpart-main">
                    <div class="webpart-main-item" style="padding: 30px;">
                    	
                    	<div class="at_loc">
		<span class="now" style="width:208px;" id="firstStep">1.填写公告标题｜内容</span>
		<span class="line_frist" id="firstStep_line"></span>
		<span style="width:208px;" id="secondStep">2.设置附件</span>
		<span class="line" id="secondStep_line"></span>
		
		<span style="width:208px;" id="thirdStep">3.确认结果</span>
		<span class="line_end" id="thirdStep_line"></span>
		</div>
                    	
                    	
                        <div class="d_formitem">
                        
                        
							<div id="step1">				
                            <table cellspacing="0" cellpadding="0"  >
                            	<tr>
                            		<td>
                            			<input type="hidden" class="inputbox" id="createUid"
										name="createUid" value="${user.saleUsersLoginId}">
                            		</td>
                            	</tr>
                                <tr>
                                    <th style="width: 60px;">
                                        公告标题:
                                    </th>
                                    <td>
                                        <input type="text" class="input-txt" id="newsTitle"
											name="newsTitle" value="${new.newsTitle}"
									style="width: 400px;"/>
									<font color="red" class="newsTitle">${newsTitle}</font>
                                    </td>
                                </tr>
                                <tr>
                                 
                                    <td   colspan="2" align="left">
										<textarea rows="6" cols="40" name="newsContent"
											id="newsContent">${new.newsContent}</textarea>

										<font color="red" class="newsContent">${newsContent}</font>
									</td>
                                </tr>
                                <tr>
                                    <td align="center">
										<input name="next" type="button" id="next" tabindex="5"
											class="linkbtn2" value="下一步">
									</td>
                                </tr>
                                
                            </table>
                             <ckfinder:setupCKEditor editor="newsContent"
							basePath="/sfa/ckfinder/" />
						<ckeditor:replace replace="newsContent" basePath="/ckeditor/"></ckeditor:replace>
						</div>
						
						
						
						<div id="step2" style="display: none;">				
                            <table cellspacing="0" cellpadding="0" class="formitem">
                                 <tr>
                                	
                              		<td colspan="2" align="left">
                              		<span  class="webpart-head-item" style="font-weight: bold;">上传附件 </span>
									<hr />
							
										<div id="fileList">  
											<c:forEach  items="${affixList}" var="affixItem">
											<div class="uoloadedFile" isDel="n" AFFIXPATH="${affixItem.SALEAFFIXITEMFILEPATH}" FILENAME="${affixItem.SALEAFFIXITEMFILENAME}" SALEAFFIXITEMID="${affixItem.SALEAFFIXITEMID}">
												<span>${affixItem.SALEAFFIXITEMFILENAME}</span>
												<a href="javascript:void(0)" onclick="sfaUpload.delUpload(this)">&nbsp;x</a>
											</div>
										</c:forEach> 
										 
										</div>
										<div id="sfaUpload" style="color: red;"></div>
									</td>
                                </tr>
                                <tr>
								<th colspan="2">
									<input name="submit" type="button" id="submit" tabindex="5"
										class="linkbtn2" value="提交">&nbsp;<input name="provi" type="button" id="provi" tabindex="5"
											class="linkbtn2" value="上一步">
								</th>
							</tr>
                                
                            </table>
                              
						</div>
						<div id="step3" style="display: none;">
				
					<div>
						<font color="red" class="add"> </font> 
							<a href="${path}/manage/news/index/getnews">返回管理公告</a>
					</div>
					
					
						</div>
						
						
                        </div>
                    </div>
                </div>
                <div class="webpart-foot">
                    <div class="webpart-foot-item">
                    </div>
                </div>
            </div>
		
		<sfa:mainFooter></sfa:mainFooter>
		
		
		
	</body>
</html>


